package com.ydjk.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ydjk.domain.JkPushTemplate;
import com.ydjk.service.IJkPushTemplateService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ydjk.common.annotation.Log;
import com.ydjk.common.core.controller.BaseController;
import com.ydjk.common.core.domain.AjaxResult;
import com.ydjk.common.enums.BusinessType;

import com.ydjk.common.utils.poi.ExcelUtil;
import com.ydjk.common.core.page.TableDataInfo;

/**
 * 推送模版Controller
 * 
 * @author ruoyi
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/system/pushTemplate")
public class JkPushTemplateController extends BaseController
{
    @Autowired
    private IJkPushTemplateService jkPushTemplateService;

    /**
     * 查询推送模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:pushTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(JkPushTemplate jkPushTemplate)
    {
        startPage();
        List<JkPushTemplate> list = jkPushTemplateService.selectJkPushTemplateList(jkPushTemplate);
        return getDataTable(list);
    }

    /**
     * 导出推送模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:pushTemplate:export')")
    @Log(title = "推送模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JkPushTemplate jkPushTemplate)
    {
        List<JkPushTemplate> list = jkPushTemplateService.selectJkPushTemplateList(jkPushTemplate);
        ExcelUtil<JkPushTemplate> util = new ExcelUtil<JkPushTemplate>(JkPushTemplate.class);
        util.exportExcel(response, list, "推送模版数据");
    }

    /**
     * 获取推送模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pushTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(jkPushTemplateService.selectJkPushTemplateById(id));
    }

    /**
     * 新增推送模版
     */
    @PreAuthorize("@ss.hasPermi('system:pushTemplate:add')")
    @Log(title = "推送模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JkPushTemplate jkPushTemplate)
    {
        return toAjax(jkPushTemplateService.insertJkPushTemplate(jkPushTemplate));
    }

    /**
     * 修改推送模版
     */
    @PreAuthorize("@ss.hasPermi('system:pushTemplate:edit')")
    @Log(title = "推送模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JkPushTemplate jkPushTemplate)
    {
        return toAjax(jkPushTemplateService.updateJkPushTemplate(jkPushTemplate));
    }

    /**
     * 删除推送模版
     */
    @PreAuthorize("@ss.hasPermi('system:pushTemplate:remove')")
    @Log(title = "推送模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(jkPushTemplateService.deleteJkPushTemplateByIds(ids));
    }
    @Scheduled(cron = "0 0 8 * * ?")
    @GetMapping("/sendMessageWx")
    public void sendMessageWx() throws IOException {
        jkPushTemplateService.sendMessageWx(1);
    }
    @Scheduled(cron = "0 0 21 * * ?")
    @GetMapping("/sendMessageWxYH")
    public void sendMessageWxYH() throws IOException {
        jkPushTemplateService.sendMessageWx(2);
    }

}
